package com.fengwk.cv4j.view.common;

import com.fengwk.cv4j.compute.Compute;
import com.fengwk.cv4j.factory.ViewFactory;
import com.fengwk.cv4j.view.View;
import com.fengwk.cv4j.view.ViewImpl;
import com.fengwk.support.exception.BaseException;

/**
 * 通用的ln算子
 * 
 * @author fengwk
 *
 * @param <T>
 */
public class LogView<T> extends ViewImpl<T> {
	
	private static final long serialVersionUID = -1806750571413781379L;
	
	public LogView(Compute<T> compute, ViewFactory<T> factory, @SuppressWarnings("unchecked") View<T>...vs) {
		super(compute, factory, vs);
		checkVs(1, vs);
	}
	
	@Override
	public T compute0() {
		return c().log(t(0));
	}

	@Override
	public View<T> gradient0(int idx) {
		if (idx == 0)
			return f().div(f().of(1), v(0));
		throw new BaseException("idx != 0");
	}

	@Override
	public String toString() {
		return "log";
	}
	
}
